<?php
namespace Admin\Model;
use Think\Model;
class CategoryModel extends Model{
	public $tableName='category';
	//添加栏目
	public function d(){

		if($this->create()){
			if($this->add()){
				return $this->updateCache();
			}	
		}else{

			return false;
		}
	}
	//编辑栏目1 AJAX
	public function edit(){
		$cid=I('cid');
		$data=$this->where("cid=$cid")->select();
		return  $data;	
	}
	//编辑栏目1 POST
	public function alter(){
		if($this->create()){
			if($this->save()){
				return $this->updateCache();
			}
			
		}else{
			return false;
		}
	}

	//删除栏目
	public function dorp(){
		if(IS_POST){
			$cid=I('cid');
			$del=$this->delete($cid);
			if($del){
				return $this->updateCache();
			}
		}else{
			return false;
		}
	}











	// 缓存
	public function updateCache(){
		S('c',null);
		$CategoryData = $this->select();
		if(empty($CategoryData)){
			return true;
		}
		$cache=S('c',$CategoryData);
		if($cache){
			return true;
		}else{
			return false;
		}

	}





}